#!/bin/sh

current_abs=$(brightnessctl get)
current_rel() {
    echo "($(brightnessctl get) + 0.5) / 1" | bc
}
max=$(brightnessctl max)
factor=3
brightness_step=$((max * factor / 100 < 1 ? 1 : max * factor / 100))

case $1 in
    # '') ;;
    'down')
        # if current value <= 3% and absolute value != 1, set brightness to absolute 1
        if [ "$(current_rel)" -le "$factor" ] && [ "$current_abs" -gt 0 ] && [ "$current_abs" -ne 1 ]; then
            brightnessctl set 1
        else
            brightnessctl set 1%-
        fi
        ;;
    'up')
        brightnessctl set 1%+
        ;;
esac

current_rel
